﻿using K;
using UnityEngine;

public class BoyAnimationCtr : MonoBehaviour
{
    public string[] strAnimator = { "play1", "play2" };
    public Animator boyAnimator;
    public AnimatorCtr animatorCtr;

    public int minTime = 6000;
    public int maxTime = 12000;
    protected bool bEnd;
    protected long begainTime;
    protected bool bInFuben;
    float lastPlaySoundTime;

    void Start ()
	{
	    bEnd = true;  begainTime = 0;
	    boyAnimator = transform.GetComponent<Animator>();
	    if (boyAnimator != null)
	    {
	        //animatorCtr = new AnimatorCtr(boyAnimator);
	    }
	}
	
	void Update () 
    {
        if (animatorCtr == null) { return; }

        animatorCtr.Update();
        if (bEnd && !bInFuben)
        {
            int n = Random.Range(0, strAnimator.Length); bEnd = false;
            animatorCtr.PlayPlayerAnimator(strAnimator[n], ELoopState.emLoopOne, 1, 1);
        }
	}
    
    public void PlayAnimationSound(int nValue)
    {
        if (ZMgr.SoundMgr != null && lastPlaySoundTime + 6 < Time.time)
        {
            lastPlaySoundTime = Time.time;
        }
    }

    public void StopAnimationCallBack(string animation, float nTimes, bool bForce)
    {
        bEnd = true;
    }

    public void PlayAnimation(string strAnimator)
    {
        animatorCtr.PlayPlayerAnimator(strAnimator, ELoopState.emLoopOne, 1, 1);
    }

    public void StopAnimation(string strAnimator)
    {
        animatorCtr.StopPlayerAnimator(strAnimator);
    }
}